package zozopo.manual;

import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.util.List;

import zozopo.database.BusiDatabaseManager;
import zozopo.manual.operations.BrandlogoOS;
import zozopo.manual.operations.BrandlogoTB;
import zozopo.manual.operations.ReleaseOS;
import zozopo.manual.operations.ReleaseTB;
import zozopo.operations.comm.DictionaryOS;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class BrandAction extends ActionSupport implements Action{
	//传入参数
	private String brand;
	private String lable;
	private String kind;
	
	//分页参数
	private int beginPageNum = 0;
	private int pageSize = 20;
	private int rowNum = 0;
	
	//传回界面参数
	private List<ReleaseTB> releaseList;
	private String brandLogo; 
	private String area;
	private List<BrandlogoTB> brandlogoList;
	private List<String> brandList;

	public String execute(){
		BusiDatabaseManager databaseConnection = new BusiDatabaseManager();
		Connection conn = databaseConnection.getConnection();
		DictionaryOS dictionaryOS = new DictionaryOS(conn);
		BrandlogoOS brandlogoOS = new BrandlogoOS(conn);
		ReleaseOS releaseOS = new ReleaseOS(conn);
		
		if(kind != null && !kind.trim().equals("")){
			rowNum = releaseOS.getRowNumByBrandAndKindAndLable(brand,kind,lable);
			releaseList = releaseOS.selectNewByBrandAndKindAndLable(brand, kind,lable, beginPageNum, pageSize);
		}else if(lable != null && !lable.trim().equals("")){
			
			rowNum = releaseOS.getRowNumByBrandAndLable(brand, lable);
			releaseList = releaseOS.selectNewByBrandAndLable(brand, lable, beginPageNum, pageSize);
		}else{
			rowNum = releaseOS.getRowNumByBrand(brand);
			releaseList = releaseOS.selectRelatedBrand(brand,beginPageNum, pageSize);
		}
		
		
		BrandlogoTB brandlogoTB= brandlogoOS.getBrandLogo(brand);
		if(brandlogoTB == null){
			brandLogo = "brand/noicon.gif";
		}else{
			brandLogo = brandlogoTB.getMinilogo_brandlogo();
		}
		
		area = dictionaryOS.getDictValue(lable);
		
		brandList = releaseOS.selectBrandHitByLable(lable, 0, 100);
		 
		brandlogoList = brandlogoOS.getBrandLogoByBrandList(brandList);
		
		databaseConnection.releaseConnection(conn);
		return SUCCESS;
	}
	
	public String getKind() {
		return kind;
	}

	public void setKind(String kind) {
		this.kind = kind;
	}

	public String getArea() {
		return area;
	}

	public void setArea(String area) {
		this.area = area;
	}

	public String getBrand() {
		
		return brand;
	}

	public void setBrand(String brand) throws UnsupportedEncodingException {
		brand = java.net.URLDecoder.decode(brand, "UTF-8");;
		this.brand = brand;
	}

	public int getBeginPageNum() {
		return beginPageNum;
	}

	public void setBeginPageNum(int beginPageNum) {
		this.beginPageNum = beginPageNum;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getRowNum() {
		return rowNum;
	}

	public void setRowNum(int rowNum) {
		this.rowNum = rowNum;
	}

	public List<ReleaseTB> getReleaseList() {
		return releaseList;
	}

	public void setReleaseList(List<ReleaseTB> releaseList) {
		this.releaseList = releaseList;
	}

	public String getBrandLogo() {
		return brandLogo;
	}

	public void setBrandLogo(String brandLogo) {
		this.brandLogo = brandLogo;
	}
	public String getLable() {
		return lable;
	}

	public void setLable(String lable) {
		this.lable = lable;
	}
	public List<BrandlogoTB> getBrandlogoList() {
		return brandlogoList;
	}

	public void setBrandlogoList(List<BrandlogoTB> brandlogoList) {
		this.brandlogoList = brandlogoList;
	}
	

	public List<String> getBrandList() {
		return brandList;
	}

	public void setBrandList(List<String> brandList) {
		this.brandList = brandList;
	}
}
